<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flutter JSBridge</title>
    <script type="text/javascript">

        function callFlutter() {
          if (window.flutter_inappwebview) {
            window.flutter_inappwebview.callHandler("test", {name: "web", message: "Hello Flutter!"})
                .then(response => {
                    console.log("Flutter 返回的数据:", response);
                });
          }
        }

        function testFlutterCallJs(message) {
            console.log('this is flutter call js ', message);
            if (window.flutter_inappwebview) {
                window.flutter_inappwebview.callHandler("showToast", {params: message})
                    .then(response => {
                        console.log("Flutter 返回的数据:", response);
                    });
            }
            return "data from js";
        }

        function testAsyncReturnFlutterCallJs(message) {
            console.log('this is flutter call async js ', message);
            setTimeout(() => {
                // 模拟异步操作，假设从服务器获得数据
                const data = { message: "Hello from JavaScript!" };
                if (window.flutter_inappwebview) {
                    window.flutter_inappwebview.callHandler("testAsyncReturnFlutterCallJsReturn", data)
                }
            }, 3000);
        }

        async function delayed(ms) {
            return new Promise(resolve => setTimeout(resolve, ms));
        }

    </script>
</head>
<body>
<h1>JSBridge Demo</h1>
<button onclick="callFlutter()">Call Flutter</button>
</body>
</html>